import Opt from '@/components/dt/info/Opt.js'
import table from '@/components/dt/table/render.js'
import dateOpt from '@/biz/option/date.js'
import nameOpt from '@/biz/option/name.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        type: 'index',
        title: '序号',
        width: 60
      },
      {
        field: 'customerPhone',
        minWidth: 120,
        header: {
          filter: {
            key: 'customerPhone',
            title: '人员手机号',
            placeholder: '请输入人员手机号',
            input: {}
          }
        }
      },
      {
        title: '抢客人',
        field: 'snatchingUserName',
        minWidth: 120,
        align: 'center',
        header: {
          filter: nameOpt.createCounselorPeople({
            key: 'snatchingUserNameOrWorkNumber',
            title: '抢客人',
            to: (info) => {
              return {
                snatchingUserNameOrWorkNumber: info.userId
              }
            }
          })
        },
        cell: {
          value: (row) => {
            return `${
              row.snatchingUserName
                ? row.snatchingUserWorkNumber
                  ? row.snatchingUserName + '(' + row.snatchingUserWorkNumber + ')'
                  : row.snatchingUserWorkNumber
                : '-'
            }`
          },
          text: {}
        }
      },
      {
        title: '抢客时间 ',
        field: 'snatchingDate',
        minWidth: 150,
        align: 'center',
        header: {
          filter: dateOpt.range({
            title: '抢客时间 ',
            placeholder: '请选择抢客时间 ',
            startKey: 'snatchingDateStart',
            endKey: 'snatchingDateEnd',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.snatchingDateStart, val.snatchingDateEnd).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('抢客时间跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.snatchingDateStart, val.snatchingDateEnd).Y >= 2)
            }
          })
        }
      },
      {
        title: '所属组织',
        field: 'orgName',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '所属案场',
        field: 'buildingName',
        minWidth: 120,
        align: 'center'
      },
      {
        title: '是否跟进',
        field: 'hasFollowedName',
        minWidth: 120,
        align: 'center',
        header: {
          filter: {
            title: '是否跟进',
            key: 'hasFollowed',
            placeholder: '请选择',
            select: {
              options: [
                { key: 1, value: '是' },
                { key: 2, value: '否' }
              ]
            }
          }
        }
      },
      {
        title: '跟进内容',
        field: 'followedContent',
        minWidth: 200,
        align: 'center'
      },
      {
        title: '是否线索转到访',
        field: 'isClueVisitName',
        minWidth: 180,
        align: 'center',
        header: {
          filter: {
            title: '是否线索转到访',
            key: 'isClueVisit',
            placeholder: '请选择',
            select: {
              options: [
                { key: 1, value: '是' },
                { key: 0, value: '否' }
              ]
            }
          }
        }
      }
    ]
  }
}

export default Column
